package udf.matching;

import java.io.IOException;

import org.apache.pig.EvalFunc;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;

import util.string.URLCleaner;

public class FallBackURL extends EvalFunc<Tuple> {

	public Tuple exec(Tuple input) throws IOException {

		Tuple output = TupleFactory.getInstance().newTuple(1);

		
		if(input ==null) return null;
		
		if(input.size()<2) return null;
		
		if(input.get(0) == null) return null;
		
		
		String url = (String) input.get(0);
		Integer level = (Integer) input.get(1);
		String domain = URLCleaner.fallBack(url, level);

		// System.out.println("Processing:" + domain + "\t" + level);
		output.set(0, domain);
		return output;

	}

}